
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Index from "../views/index.vue"
import practice from "../views/practice.vue"
import point from "../views/point.vue"
import point2 from "../views/point2.vue"
Vue.use(VueRouter)
//首页路由
const routes = [{

  path: '/',
  name: 'Home',
  component: Home,
  children: [{
    path: "/",
    redirect: "/index"
  },

  {
    path: "/index",
    name: "index",
    component: Index,
    meta: {
      title: "每时每课"
    }
  },

  //课程路由
  {
    path: '/course',
    name: "course",
    component: () => import('../views/course.vue'),
  },
  //搜索路由
  {
    path: '/search',
    name: "search",
    component: () => import('../views/search.vue'),
  },
  // 我的
  {
    path: "/mine",
    name: "mine",
    component: () => {
      return import("@/components/mine/mine")
    }
  },

  // 注册页面
  {
    path: '/smsLogin',
    name: 'smsLogin',
    component: () => {
      return import("@/components/login/smsLogin")
    }
  },
  // 找回密码页面
  {
    path: '/findPassword',
    name: 'findPassword',
    component: () => {
      return import("@/components/login/findPassword")
    }
  },
  //约课记录
  {
    path: '/sched1',
    name: 'sched1',
    component: () => import('../components/sched/sched1.vue'),
  },
  // 跳转立即约课
  {
    path: '/class',
    name: 'class',
    component: () => import('../components/sched/class.vue')
  },
  // 练习
  {
    path: '/practice',
    name: 'practice',
    component: practice,
  },
  //套卷练习
  {
    path: '/paper-package',
    name: 'paper-package',
    component: () => import('../views/paper-package.vue')
  },
  //课程路由
  {
    path: '/course',
    name: "course",
    component: () => import('../views/course.vue'),
    meta: {
      isShowTab: true
    }
  },
  //搜索路由
  {
    path: '/search',
    name: "search",
    component: () => import('../views/search.vue'),
    meta: {
      isShowTab: false
    }
  },
  //详情路由
  {
    path: '/detail',
    name: "detail",
    component: () => import('../views/detail.vue'),
    meta: {
      isShowTab: false
    }
  }
  ],

},
// 登录
{
  path: '/login',
  name: 'login',
  component: () => {
    return import("@/components/login/login")
  }
},
// 课程状况
{
  path: '/calendar',
  name: "calendar",
  component: () => import('../components/home/calendar.vue'),
},
// 讲师详情
{
  path: "/courceDetail",
  name: "courceDetail",
  component: () => import('../components/home/courceDetail.vue')
},
//课程路由
{
  path: '/course',
  name: "course",
  component: () => import('../views/course.vue'),
},
//搜索路由
{
  path: '/search',
  name: "search",
  component: () => import('../views/search.vue'),
},
{
  path: "/mine",
  name: "mine",
  component: () => {
    return import("@/components/mine/mine")
  }
},
{
  path: '/login',
  name: 'login',
  component: () => {
    return import("@/components/login/login")
  }
},
// 注册页面
{
  path: '/smsLogin',
  name: 'smsLogin',
  component: () => {
    return import("@/components/login/smsLogin")
  }
},
// 找回密码页面
{
  path: '/findPassword',
  name: 'findPassword',
  component: () => {
    return import("@/components/login/findPassword")
  }
},
//约课记录
{
  path: '/sched1',
  name: 'sched1',
  component: () => import('../components/sched/sched1.vue'),
},
// 跳转立即约课
{
  path: '/class',
  name: 'class',
  component: () => import('../components/sched/class.vue')
},
// 练习
{
  path: '/practice',
  name: 'practice',
  component: practice,
},
// 课程状况
{
  path: '/point',
  name: 'point',
  component: point,
},
// 题库侧边栏
{
  path: '/point2',
  name: 'point2',
  component: point2,
},
//仿真考试Exam
{
  path: '/Exam',
  name: 'Exam',
  component: () => import('../views/Exam'),
},
// 收藏
{
  path: '/collect',
  name: 'collect',
  component: () => import('../components/mine/collect.vue'),
},
// 修改个人资料
{
  path: '/info',
  name: 'info',
  component: () => import('../components/mine/info.vue'),
},
// 登录注册
{
  path: '/scheds',
  name: 'scheds',
  component: () => import('../components/sched/scheds'),
},
//约课记录
{
  path: '/sched1',
  name: 'sched1',
  component: () => import('../components/sched/sched1'),
},
// 跳转立即约课
{
  path: '/class',
  name: 'class',
  component: () => import('../components/sched/class.vue')
},
]
const router = new VueRouter({
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  var isLogin = localStorage.getItem('adminToken')
  // console.log(localStorage.adminToken)
  if (to.name == 'mine') {
    console.log("tooooooooooooooooooooooo")
    //判断是不是需要登录的页面
    if (!isLogin) {
      // 如果没有登录 不存在token值 就跳到登录页面
      next('/login')
    }
  }
  if (to.name == 'login') {
    if (isLogin) {
      next('/')
      return
    }
  }
  next()
})
export default router
